﻿Option Explicit On
Option Strict On
Imports DBUtilitiesLibrary
Imports DARSClassLibrary
Public Class StudentCourses
    Inherits System.Web.UI.Page
    Dim pxy As New DO_NOT_MOVE_ME_FROM_THIS_PROJECT.DARSWebservice
    Dim db As New DARSDBConnection
    Dim RecordDS As DataSet
    Dim InfoDS As DataSet

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        'Check if user is logged in
        If Session("CurrentUser") Is Nothing Then
            Response.Redirect("NotLoggedIn.aspx")
            Exit Sub
        End If
        If Not IsPostBack Then
            Dim objStudent As Student = CType(Session("CurrentUser"), Student)
            Session("StudentID") = objStudent.studentID
            view()
        End If
    End Sub

    Public Sub view()
        pxy = New DO_NOT_MOVE_ME_FROM_THIS_PROJECT.DARSWebservice
        Session("Pxy") = pxy
        Dim ds As DataSet = pxy.getStudentCourseRecord(CStr(Session("StudentID")))
        Session("ds") = ds
        Dim objdv As New DataView(ds.Tables(0))
        gvStuInfo.DataSource = objdv
        gvStuInfo.DataBind()
        InfoDS = pxy.getStudentPersonalInfo(CStr(Session("StudentID")))
        lblFirstName.Text = CStr(InfoDS.Tables(0).Rows(0)("FirstName")) & ","
        lblLastName.Text = CStr(InfoDS.Tables(0).Rows(0)("LastName"))
        lblFName.Visible = True
        lblLName.Visible = True
    End Sub

    Private Sub gvStuInfo_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles gvStuInfo.PageIndexChanging
        Dim pindex As Integer = e.NewPageIndex
        gvStuInfo.DataSource = CType(Session("ds"), DataSet)
        gvStuInfo.PageIndex = pindex
        gvStuInfo.DataBind()
    End Sub



    'Private Sub gvStuInfo_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles gvStuInfo.PreRender
    '    'Dim gv As GridView = CType(sender, GridView)
    '    'Dim gvr As GridViewRow = CType(gv.BottomPagerRow, GridViewRow)
    '    'If gvr IsNot Nothing Then
    '    '    gvr.Visible = True
    '    'End If
    'End Sub

    Private Sub gvStuInfo_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvStuInfo.RowDataBound
        If e.Row.RowType = DataControlRowType.Footer Then
            e.Row.Cells(0).Text = "Page " & (gvStuInfo.PageIndex + 1) & " of " & gvStuInfo.PageCount
        End If
    End Sub

    Protected Sub logout(ByVal sender As Object, ByVal e As EventArgs) Handles btnLogout.ServerClick
        Session.Abandon()
        Response.Redirect("NotLoggedIn.aspx")
    End Sub

    Protected Sub home(ByVal sender As Object, ByVal e As EventArgs) Handles btnhome.ServerClick
        Response.Redirect("LandingPage.aspx")
    End Sub
End Class
